package com.jvyou.subject.domain.service.impl;

import com.alibaba.fastjson2.JSON;
import com.jvyou.subject.domain.convert.SubjectCategoryBoConverter;
import com.jvyou.subject.domain.entity.SubjectCategoryBo;
import com.jvyou.subject.domain.service.SubjectCategoryDomainService;
import com.jvyou.subject.infra.basic.entity.SubjectCategory;
import com.jvyou.subject.infra.basic.service.SubjectCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 橘柚
 * @since 2024/9/26 19:35
 */
@Slf4j
@Service("subjectCategoryDomainService")
public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainService {

    @Resource
    private SubjectCategoryService subjectCategoryService;

    @Override
    public void add(SubjectCategoryBo subjectCategoryBo) {
        if (log.isInfoEnabled()) {
            log.info("SubjectCategory.add.bo:{}", JSON.toJSONString(subjectCategoryBo));
        }
        SubjectCategory subjectCategory = SubjectCategoryBoConverter.INSTANCE.boToEntity(subjectCategoryBo);
        subjectCategoryService.save(subjectCategory);
    }

    @Override
    public List<SubjectCategoryBo> queryCategory(SubjectCategoryBo subjectCategoryBo) {
        SubjectCategory subjectCategory = SubjectCategoryBoConverter.INSTANCE.boToEntity(subjectCategoryBo);
        List<SubjectCategory> subjectCategories = subjectCategoryService.queryCategory(subjectCategory);
        List<SubjectCategoryBo> subjectCategoryBos = SubjectCategoryBoConverter.INSTANCE.entityToBo(subjectCategories);
        if (log.isInfoEnabled()) {
            log.info("SubjectCategory.queryPrimaryCategory.bo:{}", subjectCategoryBos);
        }
        return subjectCategoryBos;
    }

    @Override
    public Boolean update(SubjectCategoryBo subjectCategoryBo) {
        if (log.isInfoEnabled()) {
            log.info("SubjectCategory.update.bo:{}", subjectCategoryBo);
        }
        SubjectCategory subjectCategory = SubjectCategoryBoConverter.INSTANCE.boToEntity(subjectCategoryBo);
        return subjectCategoryService.updateById(subjectCategory);
    }

    @Override
    public Boolean delete(Long id) {
        return subjectCategoryService.removeById(id);
    }
}
